#include "Color.h"

namespace RayTracer
{
    Color::Color()
    {
	this->r = 0.0f;
	this->g = 0.0f;
	this->b = 0.0f;
	this->a = 1.0f;
    }
		
    Color::Color(float r, float g, float b)
    {
	this->r = r;
	this->g = g;
	this->b = b;
	this->a = 1.0f;
    }
		
    Color::Color(float r, float g, float b, float a)
    {
	this->r = r;
	this->g = g;
	this->b = b;
	this->a = a;
    }

    Color::Color(const Color &prototype)
    {
	this->r = prototype.r;
	this->g = prototype.g;
	this->b = prototype.b;
	this->a = prototype.a;
    }

    Color Color::White()
    {
	return Color(1.0f, 1.0f, 1.0f);
    }

	Color Color::Gray()
	{
		return Color(0.5f, 0.5f, 0.5f);
	}

    Color Color::Black()
    {
	return Color(0.0f, 0.0f, 0.0f);
    }

    Color Color::Red()
    {
	return Color(1.0f, 0.0, 0.0f);
    }

    Color Color::Green()
    {
	return Color(0.0f, 1.0f, 0.0f);
    }

    Color Color::Blue()
    {
	return Color(0.0f, 0.0f, 1.0f);
    }

    Color Color::Cyan()
    {
	return Color(0.0f, 1.0f, 1.0f);
    }

    Color Color::Yellow()
    {
	return Color(1.0f, 1.0f, 0.0f);
    }
		
    Color Color::Multiply(const Color *c, float scale)
    {
	return Color(c->r * scale, c->g * scale, c->b * scale, c->a * scale);
    }
    
    Color Color::Add(const Color *a, const Color *b)
    {
	return Color(a->r + b->r, a->g + b->g, a->b + b->b);
    }

	void Color::Clamp(Color *color)
	{
		if(color->a > 1.0f)
		{
			color->a = 1.0f;
		}

		if(color->a < 0.0f)
		{
			color->a = 0.0f;
		}

		if(color->r > 1.0f)
		{
			color->r = 1.0f;
		}

		if(color->r < 0.0f)
		{
			color->r = 0.0f;
		}

		if(color->g > 1.0f)
		{
			color->g = 1.0f;
		}

		if(color->g < 0.0f)
		{
			color->g = 0.0f;
		}

		if(color->b > 1.0f)
		{
			color->b = 1.0f;
		}

		if(color->b < 0.0f)
		{
			color->b = 0.0f;
		}
	}

	void Color::ToneMap(Color *c)
	{
		c->r /= c->r + 1;
		c->g /= c->g + 1;
		c->b /= c->b + 1;
	}
};
